cmake_minimum_required(VERSION 3.0)
project(JETSONTEST)

# 查找CUDA包
find_package(CUDA REQUIRED)

# 定义路径
set(JETSON_MULTIMEDIA_API_PATH /usr/src/jetson_multimedia_api)
set(CUDA_PATH /usr/local/cuda-11.4)
set(OPENCV_PATH /usr/include/opencv4)

# 包含头文件目录
include_directories(
    ./
    ${JETSON_MULTIMEDIA_API_PATH}/include
    ${JETSON_MULTIMEDIA_API_PATH}/include/libjpeg-8b
    ${JETSON_MULTIMEDIA_API_PATH}/samples/common/algorithm/cuda
    ./jetson_enc
    ./jetson_dec
	${CUDA_INCLUDE_DIRS}
    ${CUDA_PATH}/targets/aarch64-linux/include/
    ${OPENCV_PATH}
    /usr/include/libdrm
)

# 定义源文件路径
aux_source_directory(./ JETSON_SRC)
aux_source_directory(${JETSON_MULTIMEDIA_API_PATH}/samples/common/classes JETSON_SRC)
aux_source_directory(./jetson_enc JETSON_SRC)
aux_source_directory(./jetson_dec JETSON_SRC)
aux_source_directory(./test DEMO_SRC)

# 添加编译选项
add_compile_options(-g -fpermissive)

# 链接库目录
link_directories(
    ${CUDA_PATH}/targets/aarch64-linux/lib
    /usr/lib/aarch64-linux-gnu/tegra
)

# 设置可执行文件和库文件的输出路径
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# 设置构建类型为 Release
set(CMAKE_BUILD_TYPE Release)

# 创建共享库 JetsonEnc
add_library(JetsonEnc SHARED ${JETSON_SRC})

# 为共享库添加链接库
target_link_libraries(JetsonEnc
    ${CUDA_LIBRARIES}
    pthread
    nvv4l2
    EGL
    GLESv2
    X11
    nvbufsurface
    nvbufsurftransform
    nvjpeg
    nvosd
    drm
    cuda
    cudart
)

# 创建可执行文件 demo
add_executable(demo ${DEMO_SRC})

# 为可执行文件添加链接库
target_link_libraries(demo JetsonEnc)
